//
//  HomeViewController.swift
//  MKImageBrowser3
//
//  Created by 劢克科技 on 2019/5/10.
//  Copyright © 2019 meckey. All rights reserved.
//

import UIKit

class HomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    //MARK: - Setter
    
    var images = [IndexPath: UIImage]()
    var orderImages = [[IndexPath: UIImage]]()

    //MARK: - Getter
    
    lazy var enterButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitle("点击进入", for: .normal)
        button.addTarget(self, action: #selector(handleClick), for: .touchUpInside)
        return button
    }()
    
    //MARK: - Evevts
    
    @objc fileprivate func handleClick() {
        let controller = MKSystemPhotosViewController()
        let nav = UINavigationController(rootViewController: controller)
        controller.delegate = self
        controller.setSelectedImages(images: self.images, orderImages: self.orderImages)
        present(nav, animated: true, completion: nil)
    }
}

//MARK: - < MKSystemPhotos Delegate >

extension HomeViewController: MKSystemPhotosViewControllerDelegate {
    // 获取到所有选中的图片（大图）
    func handleSelected(images: [IndexPath : UIImage], orderImages: [[IndexPath : UIImage]]) {
        self.images = images
        self.orderImages = orderImages
    }
}

//MARK: - setupUI

extension HomeViewController {
    fileprivate func setupUI() {
        view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        view.addSubview(enterButton)
        enterButton.frame = CGRect(x: 0, y: 0, width: 100, height: 17)
        enterButton.center = view.center
    }
}
